package actions;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import utils.EJBFactory;

import beans.UserManager;
import beans.UserManagerLocal;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import entities.User;

public class ListFriendsAction extends ActionSupport {

	private static final long serialVersionUID = 2L;

	@EJB
	private UserManagerLocal userManager = new UserManager();

	public String execute() {

		Map session = ActionContext.getContext().getSession();
		Integer id = (Integer) session.get("userId");

		if (id == null) {
			return ERROR;
		} else {
			// Get list of friends
			List<User> users = userManager.getFriends(id);

			if (users != null && users.size() > 0) {
				Map request = (Map) ActionContext.getContext().get("request");
				request.put("FriendList", users);
			}

		}

		return SUCCESS;

	}

}
